﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class View_PurchaseOrders : _View_PurchaseOrders
    {
        public static View_PurchaseOrders GetPurchaseOrderByID(int id)
        {
            try
            {
                View_PurchaseOrders po = new View_PurchaseOrders();
                po.Where.ID.Value = id;
                po.Query.Load();

                return po;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_PurchaseOrders.cs", "GetPurchaseOrderByID", ex.StackTrace);
                throw ex;
            }
        }

        public static View_PurchaseOrders GetUnpaidPOs(int poID)
        {
            try
            {
                View_PurchaseOrders pos = new View_PurchaseOrders();
                if (poID > 0)
                    pos.Where.SupplierID.Value = poID;
                pos.Where.Balance.Value = 0;
                pos.Where.BranchID.Value = Branches.CurrentBranchID;
                pos.Where.Balance.Operator = MyGeneration.dOOdads.WhereParameter.Operand.GreaterThan;
                pos.Query.Load();

                return pos;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_PurchaseOrders.cs", "GetUnpaidPOs", ex.StackTrace);
                throw ex;
            }
        }

        public static View_PurchaseOrders GetAllPurchaseOrdersList()
        {
            try
            {
                View_PurchaseOrders pos = new View_PurchaseOrders();
                pos.Where.BranchID.Value = Branches.CurrentBranchID;
                pos.Query.Load();
                return pos;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_PurchaseOrders.cs", "GetAllPurchaseOrdersList", ex.StackTrace);
                throw ex;
            }
        }

        public static View_PurchaseOrders GetPurchaseOrdersListByCreatedDate(string strCreatedDate)
        {
            try
            {
                View_PurchaseOrders po = new View_PurchaseOrders();
                po.Where.CreatedDate.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Like;
                po.Where.CreatedDate.Value = strCreatedDate;
                po.Where.BranchID.Value = Branches.CurrentBranchID;
                po.Query.Load();
                return po;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_PurchaseOrders.cs", "GetPurchaseOrdersListByCreatedDate", ex.StackTrace);
                throw ex;
            }
        }

        public static View_PurchaseOrders GetPurchaseOrdersListByCreatedDate(DateTime dateFrom, DateTime dateTo)
        {
            try
            {
                View_PurchaseOrders po = new View_PurchaseOrders();
                po.Where.BranchID.Value = Branches.CurrentBranchID;
                po.Where.CreatedDate.Operator = MyGeneration.dOOdads.WhereParameter.Operand.Between;
                po.Where.CreatedDate.BetweenBeginValue = dateFrom;
                po.Where.CreatedDate.BetweenEndValue = dateTo;
                po.Query.Load();
                return po;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("View_PurchaseOrders.cs", "GetPurchaseOrdersListByCreatedDate", ex.StackTrace);
                throw ex;
            }
        }
    }
}
